<template>
  <div class="mine">
    <div class="user">
      <yd-flexbox style="padding:0 .2rem">
        <yd-flexbox-item>
          <div class="userInfo">
            <router-link to="/mine/mineInfoDetail">
              <img
                :src="
                  userData.headpic || require('../../image/defaultHeadImg.jpeg')
                "
                alt
                class="avatar"
              />
            </router-link>
            <router-link to="/mine/mineInfoDetail">
              <span style="font-size:.45rem;font-weight:600">{{
                userData.nickname || '未设置'
              }}</span>
            </router-link>
          </div>
        </yd-flexbox-item>
        <router-link to="/mine/settings" class="userInfo">
          <yd-icon name="setting" size=".6rem"></yd-icon>
          <yd-icon
            name="question"
            size=".6rem"
            style="margin-left:.25rem"
          ></yd-icon>
        </router-link>
      </yd-flexbox>
    </div>
    <yd-flexbox>
      <yd-flexbox-item>
        <router-link to="/mine/myCollect" class="line-item">
          <yd-icon name="good" size=".45rem"></yd-icon>
          <span style="font-size:.33rem">收藏</span>
        </router-link>
      </yd-flexbox-item>
      <yd-flexbox-item>
        <router-link to="/mine/myComment" class="line-item">
          <yd-icon name="feedback" size=".45rem"></yd-icon>
          <span style="font-size:.33rem">评价</span>
        </router-link>
      </yd-flexbox-item>
      <yd-flexbox-item>
        <router-link to="/mine/myShare" class="line-item">
          <yd-icon name="share1" size=".45rem"></yd-icon>
          <span style="font-size:.33rem">分享</span>
        </router-link>
      </yd-flexbox-item>
      <yd-flexbox-item>
        <router-link to="/mine/myMessage" class="line-item">
          <yd-icon name="type" size=".45rem"></yd-icon>
          <span style="font-size:.33rem">消息</span>
        </router-link>
      </yd-flexbox-item>
    </yd-flexbox>

    <div class="money">
      <router-link to="/mine/myBalance">
        <div class="money-box">
          我的余额
          <span class="account">{{ '0.00' }}</span>
        </div>
      </router-link>
      <router-link to="/mine/myRecharge">
        <div class="money-box">余额充值</div>
      </router-link>
    </div>

    <div class="business">
      <yd-cell-group>
        <router-link to="/mine/myVip">
          <yd-cell-item arrow>
            <span slot="left">
              <div class="body-box">
                <yd-icon name="discount" size=".4rem"></yd-icon>
                <span>我的会员</span>
              </div>
            </span>
          </yd-cell-item>
        </router-link>
      </yd-cell-group>
      <yd-cell-group>
        <router-link to="/mine/myPoints">
          <yd-cell-item arrow>
            <span slot="left">
              <div class="body-box">
                <yd-icon name="question" size=".4rem"></yd-icon>
                <span>我的积分</span>
              </div>
            </span>
          </yd-cell-item>
        </router-link>
      </yd-cell-group>
      <yd-cell-group>
        <router-link to="/mine/myComment">
          <yd-cell-item arrow>
            <span slot="left">
              <div class="body-box">
                <yd-icon name="compose" size=".4rem"></yd-icon>
                <span>我的评论</span>
              </div>
            </span>
          </yd-cell-item>
        </router-link>
      </yd-cell-group>
      <yd-cell-group>
        <router-link to="/mine/myShare">
          <yd-cell-item arrow>
            <span slot="left">
              <div class="body-box">
                <yd-icon name="share1" size=".4rem"></yd-icon>
                <span>我的分享</span>
              </div>
            </span>
          </yd-cell-item>
        </router-link>
      </yd-cell-group>
      <yd-cell-group>
        <router-link to="/mine/shopManager">
          <yd-cell-item arrow>
            <span slot="left">
              <div class="body-box">
                <yd-icon name="video" size=".4rem"></yd-icon>
                <span>成为探店官</span>
              </div>
            </span>
          </yd-cell-item>
        </router-link>
      </yd-cell-group>
      <yd-cell-group>
        <div @click="goToSuperShare">
          <yd-cell-item arrow>
            <span slot="left">
              <div class="body-box">
                <yd-icon name="good" size=".4rem"></yd-icon>
                <span>分享达人</span>
              </div>
            </span>
          </yd-cell-item>
        </div>
      </yd-cell-group>
      <yd-cell-group>
        <router-link to="/mine/visitFriend">
          <yd-cell-item arrow>
            <span slot="left">
              <div class="body-box">
                <yd-icon name="share2" size=".4rem"></yd-icon>
                <span>邀请好友</span>
              </div>
            </span>
          </yd-cell-item>
        </router-link>
      </yd-cell-group>
      <yd-cell-group>
        <div @click="goToBusiness">
          <yd-cell-item arrow>
            <span slot="left">
              <div class="body-box">
                <yd-icon name="home-outline" size=".4rem"></yd-icon>
                <span>我是商家</span>
              </div>
            </span>
          </yd-cell-item>
        </div>
      </yd-cell-group>
      <div style="padding:0 .15rem">
        <yd-button
          class="logout-btn"
          type="danger"
          size="large"
          @click.native="logout"
          >退出账号</yd-button
        >
      </div>
    </div>
  </div>
</template>
<script>
import { userApi, sharePeopleVerify } from '@/api';
export default {
  name: 'mine',
  data() {
    return {
      userData: JSON.parse(localStorage.getItem('userData')) || {},
      showType: 1,
      money: 120.5,
      isShowModifyUsername: false,
      isShowModifyAvatar: false,
      willModifyUsername: ''
    };
  },
  mounted() {
    this.getUserInfo();
  },
  methods: {
    getUserInfo() {
      const userData = localStorage.getItem('userData');
      const userId = userData && JSON.parse(userData).userId;
      userApi({
        userId
      }).then(res => {
        this.userData = res.data.user;
      });
    },
    modifyUsername() {
      this.isShowModifyUsername = false;
      this.$dialog.toast({ mes: '修改成功', timeout: 1000 });
    },
    modifyAvatar() {
      this.isShowModifyAvatar = true;
    },
    goToBusiness() {
      if (!this.userData.discounts) this.$router.push('/business');
      else {
        this.$dialog.toast({
          mes: '你还不是商家哦'
        });
      }
    },
    goToSuperShare() {
      const isShareSuperman = false;
      if (isShareSuperman) this.$router.push('/mine/superShare');
      else {
        this.$dialog.toast({
          mes: '你还不是分享达人哦'
        });
        sharePeopleVerify();
      }
    },
    logout() {
      // localStorage.clear();
      this.$store.dispatch('Logout').then(res => {
        console.log('ok');
      });
    }
  }
};
</script>
<style scoped lang="less">
.mine {
  height: 100%;
  background: url('../../image/美食2.jpeg');
  display: flex;
  flex-direction: column;
}

.user {
  padding: 0.3rem 0 0;
  color: white;
  font-weight: 500;
}
.avatar {
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  margin-right: 0.3rem;
}

.userInfo {
  text-align: left;
  display: flex;
  align-items: center;
  font-size: 0.38rem;
}

.line-item {
  display: flex;
  flex-direction: column;
  margin: 0.45rem 0;
  color: #fff;
  font-size: 0.3rem;
}

.line {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #ccc;
  padding: 0.2rem 0;
}

.wrapper {
  background-color: #eee;
  border-radius: 0.05rem;
  padding: 0.5rem;
}
.money {
  padding: 0.1rem 0;
  border-top-left-radius: 0.3rem;
  border-top-right-radius: 0.3rem;
  background: #fff;
  font-size: 0.3rem;
  border-bottom: 0.02rem solid #eee;
}
.money-box {
  display: inline-block;
  width: 50%;
  height: 1rem;
  font-size: 0.3rem;
  line-height: 1rem;
}

.account {
  font-size: 0.42rem;
  font-weight: 600;
}

.business {
  background: #fff;
  padding: 0.1rem 0 0;
  font-size: 0.28rem;
  min-height: calc(100% - 4.65rem);

  /deep/.yd-cell-box {
    margin-bottom: 0rem;
  }
}
.body-box {
  padding: 0.2rem;
  text-align: left;
  font-size: 0.33rem;
  span {
    margin-left: 0.15rem;
  }
}

.yd-cell-item {
  padding: 0.07rem 0.25rem;
}

.logout-btn {
  height: 0.8rem;
  margin: 0.3rem 0;
  font-size: 0.36rem;
  border-radius: 0.2rem;
}
</style>
